package com.monitor.core.handler;

import com.monitor.core.bean.MessageHanlderType;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Auther: hanhui.liu
 * @Date: 2018/4/24 14:15
 * @Description:
 */
@Component
public class MessageFactory {

    private static final Logger logger = Logger.getLogger(MessageFactory.class);
    /**
    * @Description: 获取MessageHandler
    * @param messageHanlderType
    * @return MessageHandler
    * @throws
    * @author hanhui.liu
    * @date 2018/4/24 下午3:07 
    */
    @Resource
    private RabbitMQMessageHandler rabbitMQMessageHandler;

    @Resource
    private ActiveMQMessageHandler activeMQMessageHandler;

    @Resource
    private KafkaMessageHandler kafkaMessageHandler;

    @Resource
    private DefaultMessageHandler defaultMessageHandler;

    public MessageHandler getMessageHandler(MessageHanlderType messageHanlderType) {
        MessageHandler messageHandler = null;
        switch (messageHanlderType) {
            case Kafka:
                messageHandler = kafkaMessageHandler;
                break;
            case ActiveMQ:
                messageHandler = activeMQMessageHandler;
                break;
            case RabbitMQ:
                messageHandler = rabbitMQMessageHandler;
                break;
            default:
                logger.error("no designated message handler");
                break;
        }
        return messageHandler;
    }

    public MessageHandler getMessageHandler(String name) {
        //TODO 待实现
        logger.error("not complete");
//        MessageHanlderType messageHanlderType = new MessageHanlderType();
        return null;
    }

    public MessageHandler getDefaultMessageHandler() {
        return defaultMessageHandler;
    }
}
